//
//  DCTaskTitleView.m
//  YoreachCarrier
//
//  Created by 大橙子 on 2018/6/7.
//  Copyright © 2018年 中都格罗唯视. All rights reserved.
//

#import "DCTaskTitleView.h"

@interface DCTaskTitleView()
@property (nonatomic,strong) UIButton *btn;
@end
@implementation DCTaskTitleView

-(instancetype)initWithFrame:(CGRect)frame
{
    if ( self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    return self;
}
-(void)setUpUI
{
    UILabel *textLabel = [[UILabel alloc]init];
    textLabel.font = FONT(17);
    textLabel.textAlignment = NSTextAlignmentCenter;
    self.textLabel = textLabel;
    [self addSubview:textLabel];
    
    UILabel *numLabel = [[UILabel alloc]init];
    numLabel.font = FONT(14);
    numLabel.textAlignment = NSTextAlignmentCenter;
    self.numLabel = numLabel;
    [self addSubview:numLabel];
    
    UIButton *btn = [[UIButton alloc]init];
    [btn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    self.btn = btn;
    [self addSubview:btn];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.textLabel.frame = CGRectMake(0, 0, self.width, self.height*2/3);
    self.numLabel.frame = CGRectMake(0, CGRectGetMaxY(self.textLabel.frame), self.width, self.height/3);
    self.btn.frame = CGRectMake(0, 0, self.width, self.height);
}
-(void)btnDidClick:(UIButton *)sender
{
    sender.selected = !sender.selected;
    self.selected = sender.selected;
    if (_delegate && [_delegate respondsToSelector:@selector(selectedTitleView:selected:)]) {
        [_delegate selectedTitleView:self selected:sender.selected];
    }
    DCLog(@"---%s",__func__);
}
-(void)setText:(NSString *)text
{
    _textLabel.text = text;
}
-(void)setNum:(NSString *)num
{
    _numLabel.text = [NSString stringWithFormat:@"(%@)",num];
}
-(void)setSelected:(BOOL)selected
{
    _selected = selected;
    if (selected) {
        _textLabel.textColor = BlueColor;
        _numLabel.textColor = BlueColor;
    }else
    {
        _textLabel.textColor = [UIColor blackColor];
        _numLabel.textColor = [UIColor blackColor];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
